from census.models import Family, FamilyName, AdultDependant, ChildDependant
from django.contrib import admin
from django.forms import models
from django.forms.widgets import Textarea, DateInput
from django.db import models
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.contrib.auth.models import Group

class AdultDependentInline(admin.TabularInline):
    model = AdultDependant
    extra = 1
#    verbose_name = 'Adult Dependents - Age 18+'
    
class ChildDependentInline(admin.TabularInline):
    model = ChildDependant
    extra = 1
    
class FamilyNameAdmin(admin.ModelAdmin):
    list_display = ['alle', 'caste']

class FamilyAdmin(admin.ModelAdmin):
    readonly_fields = ("family_no",)
    list_filter = ['caste', 'sex', 'h_city']
    list_display = ['name', 'caste', 'known_as', 'h_city']
    search_fields = ['h_area', 'name', 'form_no']
    save_on_top = True
#    radio_fields = {'h_owenership': admin.HORIZONTAL}
    fieldsets = (
        (None,
            {'fields': 
                ('family_no', 'form_no')}),
        ('Family Head Information', 
            {'fields': 
                ('name', 'father_name', 'sex', 'known_as', 'caste', 'profession',
                 'marital_status', 'dob', 'birth_place', 'education', 'blood_group',
                 'id_no', 'mobile_no', 'email')}),
        ('Residence Address',
            {'fields':
                ('h_owenership', 'h_no', 'h_block', 'h_area', 'h_city', 'h_country', 'h_phone_no')}),
        ('Business Address',
            {'fields':
                ('business_name', 'business_addr', 'b_phone_no')}),
        ('Affiliation',
            {'fields': 
                ('member_hussainia','member_hussainia_detail', 'member_other',
                 'member_of', 'member_other_detail')}),
        ('Donation',
            {'fields': 
                ('donar_anjuman', 'anjuman_donar_receipt',
                 'donar_family_welfare', 'family_welfare_receipt')}),
        ('Voting Detail',
            {'fields': 
                ('registered_voter', 'voting_area')}),
                 
        ('Office Use Only',
            {'fields': 
                ('entered_by', 'entree_mobile_no', 'entry_date',
                'posted_by','poster_mobile_no', 'posting_date',
                'incharge', 'incharge_mobile_no', 'check_date')}),
    )
    inlines = [AdultDependentInline, ChildDependentInline]
    
    formfield_overrides = {
        models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
#        models.DateField: {'widget': DateInput(format="%d-%m-%Y")},
    }
    
#    def has_add_permission(self, request):
#        return False
    
admin.site.register(Family, FamilyAdmin)
admin.site.register(FamilyName, FamilyNameAdmin)

admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.unregister(Site)
